import 'package:eye_flutter_app/utils/storage.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/material.dart';

class StoragePage extends StatelessWidget {
  const StoragePage({Key? key}) : super(key: key);

  _setData() {
    Storage.setInt('counter', 10);
  }

  _getData() async {
    final int? counter = await Storage.getInt('counter');
    print(counter);
  }

  _removeData() async {
    final prefs = await SharedPreferences.getInstance();
    // Remove data for the 'counter' key.
    final success = await prefs.remove('counter');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('share存储'),
      ),
      body: Center(
        child: Column(
          children: [
            ElevatedButton(
              onPressed: _setData,
              child: Text('本地存储'),
            ),
            ElevatedButton(
              onPressed: _getData,
              child: Text('获取数据'),
            ),
            ElevatedButton(
              onPressed: _removeData,
              child: Text('清除缓存'),
            ),
          ],
        ),
      ),
    );
  }
}
